package cn.cqie.frame.controller;


import cn.cqie.frame.bo.add.AddClazzCourseTeacherBo;
import cn.cqie.frame.bo.query.QueryClassBo;
import cn.cqie.frame.bo.query.QueryClazzCourseTeacherBo;
import cn.cqie.frame.bo.query.QueryCourseBo;
import cn.cqie.frame.bo.query.QueryEmpBo;
import cn.cqie.frame.bo.update.UpdateClazzCourseTeacherBo;
import cn.cqie.frame.service.*;
import cn.cqie.frame.utils.MyPageHelper;
import cn.cqie.frame.vo.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHL
 * @since 2021-10-07
 */
@RestController
@Api("课表管理")
public class ClazzCourseTeacherController {
    @Autowired
    private ClazzCourseTeacherService clazzCourseTeacherService;
    @Autowired
    private ClazzService clazzService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private EmpService empService;
    /**
     * 新增课表信息
     * @param bo
     * @return
     */
    @ApiOperation("新增课表信息")
    @PostMapping(value = "/schedule/saveSchedule")
    public ResultVo<Void> saveSchedule(@Valid @RequestBody AddClazzCourseTeacherBo bo) {
        System.out.println(bo);
        clazzCourseTeacherService.saveCct(bo);
        return ResultVo.success();
    }
    /**
     * 更新课表信息
     * @param bo
     * @return
     */
    @ApiOperation("更新课表信息")
    @PostMapping(value = "/schedule/updateSchedule")
    public ResultVo<Void> updateSchedule(@RequestBody UpdateClazzCourseTeacherBo bo) {
        Boolean aBoolean = clazzCourseTeacherService.updateSchedule(bo);
        return aBoolean ? ResultVo.success() : ResultVo.error("更新失败");
    }
    /**
     * 查询课表信息分页
     * @param bo
     * @return
     */
    @ApiOperation("查询课表信息分页")
    @GetMapping(value = "/schedule/scheduleInfoPage")
    public ResultVo<PageInfo<ClazzCourseTeacherVo>> getPageList(QueryClazzCourseTeacherBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(clazzCourseTeacherService.list(bo)));
    }
    /**
     * 删除课表信息
     * @param id
     * @return
     */
    @ApiOperation("删除课表信息")
    @DeleteMapping("/schedule/deleteSchedule/{Id}")
    public ResultVo<Void> deleteSchedule(@PathVariable Integer id) {
        Boolean delete = clazzCourseTeacherService.deleteSchedule(id);
        return delete ? ResultVo.success() : ResultVo.error("删除失败");
    }
    /**
     * 获取班级备选项
     * @param bo
     * @return
     */
    @ApiOperation("获取班级备选项")
    @PostMapping(value = "/schedule/listAllClazz")
    public ResultVo<PageInfo<ClassVo>> listAllClazz(QueryClassBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(clazzService.list(bo)));
    }
    /**
     * 获取课程备选项
     * @param bo
     * @return
     */
    @ApiOperation("获取课程备选项")
    @PostMapping(value = "/schedule/listAllCourse")
    public ResultVo<PageInfo<CourseVo>> listAllCourse(QueryCourseBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(courseService.list(bo)));
    }
    /**
     * 获取教师备选项
     * @param bo
     * @return
     */
    @ApiOperation("获取教师备选项")
    @PostMapping(value = "/schedule/listAllTeacher")
    public ResultVo<PageInfo<EmpVo>> listAllTeacher(QueryEmpBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(empService.list(bo)));
    }

}

